/* 
 * File:   main.cpp
 * Author: manu
 *
 * Created on 24 avril 2010, 16:10
 */
#include <stdlib.h>
#include <iostream>
//from package libopenal-dev
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alext.h>
//from package libalut-dev
#include <AL/alut.h>

#include "utils.h"


/*
 * 
 */
int main(int argc, char** argv) {

// Initialize OpenAL and clear the error bit.

    alutInit(&argc, argv);
    alGetError();

//The function 'alutInit' will setup everything that the Alc needs to do for us. Basically Alut creates a single OpenAL context through Alc and sets it to current. On the Windows platform it initializes DirectSound. We also do an initial call to the error function to clear it. Every time we call 'glGetError' it will reset itself to 'AL_NO_ERROR'.
    // Load the wav data.
    if (LoadALData() == AL_FALSE)
        return -1;

    SetListenerValues();

    // Setup an exit procedure.
    atexit(KillALData);

//We will check to see if the wav files loaded correctly. If not we must exit the program. Then we update the listener values, and finally we set our exit procedure.
    ALubyte c = ' ';

    

    while (c != 'q')
    {
        std::cin >> c ;

        //if (<<LoadALData() == AL_FALSE)
        //return -1;

        switch (c)
        {
            // Pressing 'p' will begin playing the sample.
            case 'p':
                //play() ;
                //if (alGetError() != AL_NO_ERROR)
                //    return AL_FALSE;
                //alGenBuffers(1, &Buffer);
                //Buffer = alutCreateBufferFromFile("data/crapaud.wav");
                //alGenSources(1, &Source);
                //alSourcei (Source, AL_BUFFER,   Buffer   );
                alSourcePlay(Source);
                
                break;


            // Pressing 's' will stop the sample from playing.
            case 's': alSourceStop(Source); break;

            // Pressing 'h' will pause (hold) the sample.
            case 'h': alSourcePause(Source); break;
        };
    }

    return 0;
}

